<template>
  <el-container id="roothelp">
    <el-main>
      <el-tabs tab-position="top" class="el-tabs" >
        <el-tab-pane label="并发测试">
          <el-button type="primary" @click="testPing">执行1次</el-button>
          <el-button type="primary" @click="testPing10">执行10次</el-button>
        </el-tab-pane>
        <el-tab-pane label="提供给HIS的接口">
          <el-tabs tab-position="left" >

            <el-tab-pane :label="ob.name" v-for="(ob,index) in hisInterfaceOuts" :key="ob.name">
              <el-form  ref="form"  label-width="120px" label-position="top">
                <el-form-item label="接口类型">
                  <el-input v-model="ob.type" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求地址">
                  <el-input v-model="ob.addr"></el-input>
                </el-form-item>
                <el-form-item label="请求方法" readonly>
                  <el-input v-model="ob.methodName"></el-input>
                </el-form-item>
                <el-form-item label="请求参数" >
                  <el-input  v-if="ob.paramType && ob.paramType =='string'"
                    type="textarea"
                    placeholder="请输入内容"
                    v-model="ob.param"
                    :autosize="{ minRows: 2, maxRows: 20}"
                  ></el-input>
                  <vueJsonEditor v-else v-model="ob.param" :show-btns="false" :expandedOnStart="true" :mode="'code'" lang="zh"  ></vueJsonEditor>
                </el-form-item>
                <el-form-item >
                  <el-button type="primary" @click="testApi(ob)">执行</el-button>
                  <el-button type="primary" @click="ob.serverMsg = ''">重置</el-button>
                </el-form-item>
                <el-form-item label="服务器响应结果" >
                  <JsonViewer v-model="ob.serverMsg"  />
                  <!--<el-input
                    type="textarea"
                    readonly
                    v-model="ob.serverMsg"
                    :autosize="{ minRows: 2, maxRows: 20}"
                  ></el-input>-->
                </el-form-item>

              </el-form>
            </el-tab-pane>

          </el-tabs>
        </el-tab-pane>

        <el-tab-pane label="本地模拟HIS的接口">
          <el-tabs tab-position="left" >
            <el-tab-pane :label="ob.name" v-for="(ob,index) in hisInterfaceIns" :key="ob.name">
              <el-form  ref="form"  label-width="120px" label-position="top">
                <el-form-item label="接口类型">
                  <el-input v-model="ob.type" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求地址">
                  <el-input v-model="ob.addr" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求方法" readonly>
                  <el-input v-model="ob.methodName"></el-input>
                </el-form-item>
                <el-form-item label="请求参数" >
                  <el-input
                    type="textarea"
                    placeholder="请输入内容"
                    v-model="ob.param"
                    :autosize="{ minRows: 2, maxRows: 20}"
                  ></el-input>
                </el-form-item>
                <el-form-item >
                  <el-button type="primary" @click="testApi(ob)">执行</el-button>
                  <el-button type="primary" @click="ob.serverMsg = ''">重置</el-button>
                </el-form-item>

                <el-form-item label="服务器响应结果" >
                  <JsonViewer v-model="ob.serverMsg" :expand-depth=5  />
                  <!--<el-input
                    type="textarea"
                    readonly
                    v-model="ob.serverMsg"
                    :autosize="{ minRows: 2, maxRows: 20}"
                  ></el-input>-->
                </el-form-item>

              </el-form>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>

        <el-tab-pane label="his相关调用接口">
          <el-tabs tab-position="left" >
            <el-tab-pane :label="ob.name" v-for="(ob,index) in hisInterfaces" :key="ob.name">
              <el-form  ref="form"  label-width="120px" label-position="top">
                <el-form-item label="接口类型">
                  <el-input v-model="ob.type" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求类型">
                  <el-input v-model="ob.postType" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求地址">
                  <el-input v-model="ob.addr" readonly></el-input>
                </el-form-item>
                <el-form-item label="请求参数" >
                  <el-input v-model="ob.param" type="textarea" :autosize="{ minRows: 1, maxRows: 40}" ></el-input>
                </el-form-item>
                <el-form-item >
                  <el-button type="primary" @click="testApi(ob)">执行</el-button>
                  <el-button type="primary" @click="ob.serverMsg = ''">重置</el-button>
                </el-form-item>

                <el-form-item label="服务器响应结果" >
                  <el-input v-html="ob.serverMsg" size="medium" type="textarea" :autosize="{ minRows: 1, maxRows: 40}" readonly/>
                </el-form-item>

              </el-form>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
        <el-tab-pane label="HRP相关调用接口">
          <el-tabs tab-position="left" >
            <el-tab-pane :label="ob.name" v-for="(ob,index) in HRPInterfaces" :key="ob.name">
              <el-form  ref="form"  label-width="120px" label-position="top" >
                <h5>接口类型:{{ob.type}}，格式:{{ob.strType}}，请求类型:{{ob.paramType}}</h5>
                <h5>请求地址:{{ob.addr}}，请求头:{{ob.paramHead}}</h5>
                <el-form-item label="请求体" >
                  <el-input v-model="ob.paramBody" type="textarea" :autosize="{ minRows: 1, maxRows: 40}" ></el-input>
                </el-form-item>
                <el-form-item >
                  <el-button type="primary" @click="testApi(ob)">执行</el-button>
                  <el-button type="primary" @click="ob.reset()">重置</el-button>
                </el-form-item>

                <el-form-item label="服务器响应结果" >
                  <pre style="white-space: break-spaces;">{{ob.serverMsg}}</pre>
                </el-form-item>

              </el-form>
            </el-tab-pane>
          </el-tabs>
        </el-tab-pane>
      </el-tabs>
    </el-main>
  </el-container>
</template>

<script>
/*eslint-disable */
import JsonViewer from 'vue-json-viewer'
import vueJsonEditor from 'vue-json-editor'

export default {
  name: 'roothelp',
  data() {
    return {
      hisInterfaceOuts: [
        {
          name: '根据唯一码查询库存-ws方式',
          type: 'SOAP',
          paramType: 'string',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'queryByUniqueCode',
          param: 'SN或者RFID字符串或XML' ,
          serverMsg: ''
        },
/*        {
          name: '病人计费登记',
          type: 'SOAP',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'execPatientBillRegister',
          param: '数据格式待确定',
          serverMsg: ''
        },*/
        {
          name: '病人计费(JSON)-ws方式',
          type: 'SOAP',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'execPatientBill',
          param: {
            ref_key:'HIS20190630009',
            bus_date:'2019-06-30 11:11:11',
            dept_code_use:'4001',
            dept_code_exec:"4001",
            bill_flag:'1',
            user:"操作人名称",
            inpatient_no:"住院号【选填】",
            outpatient_no:"门诊号【选填】",
            oprt_code:"手术单号【选填】",
            bill_dtl:
              [{
                unique_code:"SN20080012",
                his_code:"0101031000972"
              },{
                unique_code:"SN20080012",
                his_code:"0101031000972"
              }
              ]
          },
          serverMsg: ''
        },
        {
          name: '病人计费(XML)-ws方式',
          type: 'SOAP',
          paramType: 'string',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'execPatientBill',
          param: `<?xml version="1.0" encoding="utf-8"?>
                    <root>
                      <ref_key>病人收费单流水号，日后对账用</ref_key>
                      <bus_date>2021-3-18</bus_date>
                      <dept_code_use>消耗科室代码（病人所属科室）</dept_code_use>
                      <dept_code_exec>执行科室代码</dept_code_exec>
                      <oprt_code>手术单号</oprt_code>
                      <bill_flag>1</bill_flag>
                      <user>操作人(staff_code)</user>
                      <inpatient_no>住院号【选填】</inpatient_no>
                      <outpatient_no>门诊号|患者门诊唯一标识【选填】</outpatient_no>
                      <dtls>
                        <unique_code>唯一码，有的话为高值</unique_code>
                        <his_code>HIS收费编码</his_code>
                      </dtls>
                    </root>`,
          serverMsg: ''
        },
        {
          name: '病人计费批操作-ws方式',
          type: 'SOAP',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'execPatientBillBatch',
          param:[
            {
              unique_code:"SN20080012",
              his_code:"0101031000972",
              ref_key:"HIS20190630009",
              bus_date:"2019-06-30 11:11:11",
              dept_code_use:"4001",
              dept_code_exec:"4001",
              bill_flag:"1",
              user:"操作人名称",
              inpatient_no:"住院号【选填】",
              patient_no:"病案号",
              outpatient_no:"门诊号【选填】",
              oprt_code:"手术单号【选填】"
            },
            {
              unique_code:"SN20080013",
              his_code:"0101031000972",
              ref_key:"HIS20190630009",
              bus_date:"2019-06-30 11:11:11",
              dept_code_use:"4001",
              dept_code_exec:"4001",
              bill_flag:"1",
              user:"操作人名称",
              inpatient_no:"住院号【选填】",
              patient_no:"病案号",
              outpatient_no:"门诊号【选填】",
              oprt_code:"手术单号【选填】"
            }
          ],
          serverMsg: ''
        },
        {
          name: '计费项目变更-ws方式',
          type: 'SOAP',
          paramType: 'string',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapHis?wsdl',
          methodName: 'execChargeChange',
          param: {
            "matr_code_his":"F00000071126",
            "matr_name_his":"同种骨植入材料",
            "price_patient_adult":"34332",
            "price_patient_child":"34332",
            "matr_code_hrp":"99999",
            "is_disabled":"1"
          },
          serverMsg: ''
        },
        {
          name: '根据唯一码查询库存-http方式',
          type: 'HTTP',
          paramType: 'string',
          addr: process.env.VUE_APP_BASE_API + 'spdAms/his/queryByUniqueCode/SN2310000026',
          param: 'url带参' ,
          serverMsg: ''
        },
        {
          name: '病人计费批量-http方式',
          type: 'HTTP',
          addr: process.env.VUE_APP_BASE_API + 'spdAms/his/execPatientBillBatch',
          param: {
            "dataArr": [
              {
                "unique_code": "SN2310000026",
                "his_code": "20231026001",
                "ref_key": "20231026001",
                "bus_date": "2023-10-26 11:11:11",
                "dept_code_use": "002001",
                "dept_code_exec": "002001",
                "bill_flag": "1",
                "user": "张三",
                "inpatient_no": "in20231026001",
                "patient_no": "ba20231026001",
                "outpatient_no": "out20231026001",
                "oprt_code": "oprt20231026001"
              }
            ]
          },
          serverMsg: ''
        }
      ],
      hisInterfaceIns: [
        {
          name: '获取手术信息',
          type: 'SOAP',
          addr: process.env.VUE_APP_BASE_API + 'webservice/SOAPMock?wsdl',
          methodName: 'getOprt',
          param: '无',
          serverMsg: ''
        },
        {
          name: '获取病人信息',
          type: 'SOAP',
          addr: process.env.VUE_APP_BASE_API + 'webservice/SOAPMock?wsdl',
          methodName: 'getPatient',
          param: '无',
          serverMsg: ''
        }
      ],
      fsdInterfaceIns: [
        {
          name: '入库明细通知接口',
          type: 'HTTP',
          addr: 'apiFsd/WiNotify',
          param: {
            OpStorageCode: 'WL00001',
            OpApiVersion: '0.5',
            OpFsdType: 'fsd100',
            OpGUID: 'OpGUID2020',
            OpNumber: '1234',
            WiType: 'WI',
            RFIDS: [
              {
                rfid: 'rfid2020001',
                matrName: '导管'
              },
              {
                rfid: 'rfid2020002',
                matrName: '导丝'
              }
            ]
          },
          serverMsg: ''
        },
        {
          name: '出库明细通知接口',
          type: 'HTTP',
          addr: 'apiFsd/WoNotify',
          param: {
            OpStorageCode: 'WL00001',
            OpApiVersion: '0.5',
            OpFsdType: 'fsd100',
            OpGUID: 'OpGUID2020',
            OpNumber: '1234',

            WoType: 'OP',
            OperationRoomCode: '002022',
            RFIDS: [
              {
                rfid: 'rfid2020001',
                matrName: '导管'
              },
              {
                rfid: 'rfid2020002',
                matrName: '导丝'
              }
            ]
          },
          serverMsg: ''
        },
        {
          name: '实时库存通知接口',
          type: 'HTTP',
          addr: '/apiFsd/ScanNotify',
          param: {
            OpStorageCode: 'WL00001',
            OpApiVersion: '0.5',
            OpFsdType: 'fsd100',
            OpGUID: 'OpGUID2020',
            OpNumber: '1234',
            RFIDS: [
              'F4000000001'
            ]
          },
          serverMsg: ''
        },
        {
          name: '定数包消耗通知接口',
          type: 'HTTP',
          addr: 'apiFsd/Consume',
          param: {
            OpStorageCode: 'WL00001',
            OpApiVersion: '0.5',
            OpFsdType: 'fsd100',
            OpGUID: 'OpGUID2020',
            OpNumber: '1234',

            RFIDS: [
              {
                rfid: 'rfid2020001',
                matrName: '导管'
              }
            ]
          },
          serverMsg: ''
        }
      ],
      sysInterfaceIns: [
        {
          name: '科室消耗单科室修改',
          type: 'HTTP',
          addr: 'dept/oprt_use/updateInfo',
          param: {
            busKey: 'WL00001',
          },
          serverMsg: ''
        }
      ],

      thirdParts: [
        {
          name: '打印写RFID标签接口',
          type: 'HTTP',
          addr: '/spdAms/printRFID',
          postType: 'post',
          param: {
              "data": {
                "Code": "制标单号",
                "ConsumerGoodsRFIDCreateList": [{

                    "ItemID": "商品ID-00212001",
                    "GoodsName": "品名-耗材1",
                    "GoodsDesc": "规格-3*2",
                    "ProductLocation": "厂家-南京健康",
                    "BatchID": "批次ID",
                    "BatchNo": "批次号-20210510011",
                    "UnitPackage": "定数包系数-5",
                    "SPDuniqueCode": "D9100037058000012354",
                    "ExpiredDate": "商品有效期-20220510",
                    "CreatedLocalDtm": "1900-01-01 14:31:59"
                  },
                  {
                    "ItemID": "商品ID",
                    "GoodsName": "品名-耗材1",
                    "GoodsDesc": "规格-5*10",
                    "ProductLocation": "厂家-南京健康",
                    "BatchID": "批次ID",
                    "BatchNo": "批次号-20210510002",
                    "UnitPackage": "定数包系数-10",
                    "SPDuniqueCode": "D9100037058000128888",
                    "ExpiredDate": "商品有效期-20220510",
                    "CreatedLocalDtm": "1900-01-01 14:31:59"
                  }
                ]
              }
            },
          serverMsg: ''
        }
      ],
      ajaxs: [
        {
          name: '请领需求提交审核',
          type: 'HTTP',
          addr: '/dept/apply/flow_change',
          param: {
            "flowKey": "std_audit_apply_demand",
            "buttonKey": "submit",
            "busIdName": "id",
            "busTable": "dept_apply",
            "flowStatusTextFrom": "制单",
            "flowStatusTextTo": "待审核",
            "busTypeName": "请领需求",
            "busId": "1481153107170963457",
          },
          serverMsg: ''
        }
      ],
      hisInterfaces: [
        {
          name: '同步HIS科室',
          type: 'HTTP',
          postType: 'post',
          addr: '/his/syncDept',
          param: ``,
          serverMsg: ''
        },
        {
          name: '同步HIS手术',
          type: 'HTTP',
          postType: 'post',
          addr: '/his/get_oprt',
          param: ``,
          serverMsg: ''
        },
        {
          name: '同步HIS计费明细',
          type: 'HTTP',
          postType: 'post',
          addr: '/his/refreshBillHis',
          param: ``,
          serverMsg: ''
        },
        {
          name: '实时查询his病人接口',
          type: 'HTTP',
          postType: 'get',
          addr: '/his/getHisPatient',
          param: `?no=病案号|患者唯一标识|住院号|门诊号&type=0:住院病人；1:门诊病人`,
          serverMsg: ''
        }
      ],
      HRPInterfaces: [
        {
          name: '耗材变更',
          type: 'SOAP',
          paramType: 'string',
          strType: 'xml',
          addr: process.env.VUE_APP_BASE_API + 'webservice/soapOut?wsdl',
          methodName: 'callBase',
          reset(){
            this.serverMsg = ''
            this.paramBody = this.paramBodyOld
          },
          paramHead: `<root>
   <serverName>matr</serverName>
</root>`,
          paramBody: `<root>
    <sp_code>供应商代码（HRP系统代码）</sp_code>
    <category_code>品类代码</category_code>
    <matr_code>商品代码（HRP商品编码）</matr_code>
    <matr_name>品名</matr_name>
    <matr_spec>品规</matr_spec>
    <matr_unit>单位（单品单位）</matr_unit>
    <is_finance_disabled>财务禁用0：不是；1：是 </is_finance_disabled>
    <is_disabled>物流禁用0：不是；1：是</is_disabled>
    <is_omoc>一物一码，0：不是；1：是</is_omoc>
    <mfg_code>厂商代码</mfg_code>
    <certificate_exp>注册证效期</certificate_exp>
    <certificate_no>注册证号</certificate_no>
    <mfg_name>厂商名称</mfg_name>
    <warehouse>所属仓库</warehouse>
    <price_sp>供应商价格（单品价格）</price_sp>
</root>`,
          paramBodyOld: `<root>
    <sp_code>供应商代码</sp_code>
    <category_code>品类代码</category_code>
    <matr_code>商品代码（HRP商品编码）</matr_code>
    <matr_name>品名</matr_name>
    <matr_spec>品规</matr_spec>
    <matr_unit>单位（单品单位）</matr_unit>
    <is_finance_disabled>财务禁用0：不是；1：是 </is_finance_disabled>
    <is_disabled>物流禁用0：不是；1：是</is_disabled>
    <is_omoc>一物一码，0：不是；1：是</is_omoc>
    <mfg_code>厂商代码</mfg_code>
    <certificate_exp>注册证效期</certificate_exp>
    <certificate_no>注册证号</certificate_no>
    <mfg_name>厂商名称</mfg_name>
    <warehouse>所属仓库</warehouse>
    <price_sp>供应商价格（单品价格）</price_sp>
</root>`,
          paramType: `1`,
          serverMsg: ''
        }
      ]
    }
  },
  components: {
    JsonViewer, vueJsonEditor
  },
  methods: {
    testApi(ob, num) {
      ob.serverMsg = {msg: '请稍候'}
      /* eslint-disable */
      if (ob.type == 'SOAP') {
        let addr = '/apiMock/callLocalSoap';
        this.utilVue.loadShow(true)
        this.$ajax.post(addr, ob).then((response) => {
          this.utilVue.loadHide()
          console.log('testApi.response', response)
          if(response.code == 0) {
            if (ob.strType && ob.strType == 'xml') {
              ob.serverMsg = response.data
            }else {
              ob.serverMsg = JSON.parse(response.data);
              if (ob.serverMsg) {
                try {
                  JSON.parse(ob.serverMsg.data);
                  ob.serverMsg.data=JSON.parse(ob.serverMsg.data);
                }catch (e){
                }
              }
            }
          }
        })
      }else if (ob.type == 'HTTP') {
        let exeNum =1;
        if (!isNaN(num)) exeNum = num
        for(let i=0;i<exeNum;i++){
          if (exeNum>1) this.utilMessage.success('第'+(i+1)+'次调用开始')
          this.utilVue.loadShow(true)
            let postType = ob.postType?ob.postType : 'post'
            let addr = ob.addr
            if (postType == 'get' && ob.param) addr+= ob.param
            this.$ajax[postType](addr, ob.param).then((response) => {
            if(response.code == 0) ob.serverMsg =response;
            if (num>1) {
              ob.serverMsg.msg= {msg: '调用了'+exeNum+'次，请查询控制台'};
              console.log('第'+(i+1)+'次调用,code:',response.code,response.msg)
            }
            this.utilVue.loadHide()
          })
        }
      }
    },
    testAjax(ob, num) {
      ob.serverMsg = '请稍候'
      let tempMsgArr = new Array(10)
      for(let i=0;i< 10;i++){
        ob.serverMsg = ''
        this.utilMessage.success('第'+(i+1)+'次调用开始')
        this.utilVue.loadShow(true)

        this.$ajax.post(ob.addr, ob.param).then((response) => {
          tempMsgArr[i] = '第'+(i+1)+'次调用,响应时间:' + new Date().format('yyyy-MM-dd HH:mm:ss.SSS')+'，返回：' + response.msg
          console.log('第'+(i+1)+'次调用,响应时间:' + new Date().format('yyyy-MM-dd HH:mm:ss.SSS')+'，返回：',response)
          this.utilVue.loadHide()
          if (i == 9) {
            ob.serverMsg = tempMsgArr.join('<br>')
          }
        })
      }
    },
    testPing10() {
      let tempMsgArr = new Array(10)
      this.utilMessage.success('请看控制台')
      for(let i=0;i< 10;i++){
        console.log('第'+(i+1)+'次调用开始')
        this.$ajax.post('/LMSAms/ping').then((response) => {
          tempMsgArr[i] = '第'+(i+1)+'次调用,响应时间:' + new Date().format('yyyy-MM-dd HH:mm:ss.SSS')+'，返回：' + response.msg
          console.log('第'+(i+1)+'次调用,响应时间:' + new Date().format('yyyy-MM-dd HH:mm:ss.SSS')+'，返回：',response.msg)
        }).catch(e => {
          console.log('第'+(i+1)+'次调用,异常:' ,e)
        })
      }
    },
    testPing() {
      this.$ajax.post('/LMSAms/ping').then((response) => {
        console.log('响应时间:' + new Date().format('yyyy-MM-dd HH:mm:ss.SSS')+'，返回：',response.msg)
      }).catch(e => {
        console.log('次调用,异常:' ,e)
      })
    }
  },
  props: [],
  created() {


  },
  computed: {

  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
  #roothelp .el-tabs__header{
    width: 50px !important;
  }
</style>
